<?php

namespace app\admin\model\superdata;

use think\Db;
use think\Model;


class Activitycategory extends Model
{

    const ACTIVITY_STATUS_1 = 1;
    const ACTIVITY_STATUS_0 = 0;

    

    // 表名
    protected $name = 'activity_category';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;



    // 追加属性
    protected $append = [
        'status_text',
    ];

    //新加状态字段
    public function getStatusList()
    {
        return ['0' => __('category_status 0'),'1' => __('category_status 1')];
    }
    //获取状态字段
    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : $data['status'];
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }



    /*
     * 查找分类列表信息
     */
    public function getCategoryList(){
        $where['status'] = self::ACTIVITY_STATUS_1;
        $list = $this->getModel()->where($where)->select();
        $list = collection($list)->toArray();
        $Arr = [];
        if($list){
            foreach($list as $k=>$v){
                $Arr[$v['id']] = $v['name'];
            }
        }
        unset($list);
        return $Arr;
    }

    /*
     * 查找分类名称
     */
    public function getcateNameById($id){
        $where['status'] = self::ACTIVITY_STATUS_1;
        $res = Db::name('activity_category')->where('id',$id)->where($where)->field('name')->find();
        if($res){
            $name = $res['name'];
        }else{
            $name = '';
        }
        return $name;
    }

}
